<!DOCTYPE html>
<html lang="zh-CN"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      layout:decorator="model/boardModel">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link rel="stylesheet" th:href="@{/plugins/bootstrap-select/bootstrap-select.min.css}"/>
    <script th:src="@{/plugins/area/CityJson.js}"></script>
    <script th:src="@{/plugins/area/ProJson.js}"></script>
    <script th:src="@{/plugins/area/DistrictJson.js}"></script>
    <title>员工列表</title>

</head>
<body>

<div th:fragment="pagenav" th:remove="tag">
    <div th:replace="model/nav :: pageheader ('员工管理','员工管理')"></div>
</div>

<div th:fragment="content" th:remove="tag">


    <div class="row">
        <div class="col-xs-12">

            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">查询条件</h3>
                    <div class="box-tools pull-right">
                        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form role="form" id="queryForm" th:action="@{/emp/list}" method="post" >
                    <div class="box-body">
                        <div class="row">
                            <div class="col-xs-3">
                                <input type="text" th:name="loginName"  class="form-control input-sm" placeholder="账户"/>
                            </div>
                            <div class="col-xs-3">
                                <input type="text" th:name="empName" class="form-control input-sm" placeholder="姓名"/>
                            </div>
                            <div class="col-xs-3">
                                <input type="text" th:name="phone" class="form-control input-sm" placeholder="电话"/>
                            </div>
                            <shiro:hasRole name="sys_ka">
                                <input type="hidden" th:name="kaId" th:value="${session.authUser.userId}"/>
                            </shiro:hasRole>
                            <shiro:hasRole name="sys_bd">
                                <input type="hidden" th:name="cityAgencyId" th:value="${session.authUser.userId}"/>
                            </shiro:hasRole>
                            <shiro:hasRole name="sys_agency">
                                <input type="hidden" th:name="agencyId" th:value="${session.authUser.userId}"/>
                            </shiro:hasRole>
                            <shiro:hasRole name="sys_nationwide">
                                <input type="hidden" th:name="nationwideId" th:value="${session.authUser.userId}"/>
                            </shiro:hasRole>
                            <shiro:hasRole name="sys_kaAgency">
                                <input type="hidden" th:name="kaAgencyId" th:value="${session.authUser.userId}"/>
                            </shiro:hasRole>
                        </div>
                    <br/>
                    <div class="row">
                        <div class="col-xs-3">
                            <input type="text" th:name="kaName" class="form-control input-sm" placeholder="客户名称"/>
                        </div>
                        <div class="col-sm-6">
                            <select id="selProvince" name="provinceId" style="width: 140px;height: 34px;float:left" class="form-control select2" >
                                <option value="">--省份--</option>
                            </select>
                            <select id="selCity" name="cityId" style="width: 140px;height: 34px;float:left"  class="form-control select2" >
                                <option value="">--城市--</option>
                            </select>
                        </div>
                        <div class="col-xs-3">
                            <button id="btn-query" type="button" class="btn btn-primary pull-right btn-sm">查询</button>
                        </div>
                    </div>
                    </div>
                    <!-- /.box-body -->

                    <div class="box-footer">

                    </div>
                </form>
            </div>


            <div class="box">

                <!-- /.box-header -->
                <div class="box-body">
                    <div class="table-responsive">
                        <table id="dataTable" class="table table-striped table-bordered table-hover table-condensed">

                            <thead >
                            <tr>
                                <th>账户</th>
                                <th>姓名</th>
                                <th>电话</th>
                                <th>职务</th>
                                <th>状态</th>
                                <th>佣金比例(%)</th>
                                <th>总金额</th>
                                <th>冻结金额</th>
                                <th>可提现</th>
                                <th>创建时间</th>
                                <shiro:hasAnyRoles name="sys_agency,sys_nationwide">
                                    <th>操作</th>
                                </shiro:hasAnyRoles>
                            </tr>
                            </thead>
                        </table>
                    </div>
                    <!--<div th:include="model/page :: pager" th:remove="tag"></div>-->
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>

    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header" style="background-color: #307095;">
                    <button type="button" class="close" data-dismiss="modal" id="btn_close" >
                        <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel2">员工-编辑</h4>
                </div>

                <div class="modal-body">
                    <form class="form-horizontal"  id="editForm"  method="post">
                        <input type="hidden" class="form-control" name="empId"/>
                        <input type="hidden" name="status" id="empStatus"/>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">用户名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="loginName"
                                       data-rule-required="true" data-msg-required="请录入用户名"
                                       data-rule-minlength="7" data-msg-minlength="用户名最少7个字符"
                                       data-rule-maxlength="8" data-msg-maxlength="用户名最大为8个字符"
                                       data-rule-commonString ="true"
                                       placeholder="用户名(7-8位字母或数字)"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">姓名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="empName" placeholder="姓名"
                                       data-rule-required="true" data-msg-required="请录入姓名"
                                       data-rule-minlength="2" data-msg-minlength="姓名最少2个字符"
                                       data-rule-maxlength="20" data-msg-maxlength="姓名最大为20个字符"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">身份证号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="cardNo" placeholder="身份证号"
                                       data-rule-required="true" data-msg-required="请录入身份证号"
                                       data-rule-isIdCardNo="TRUE"  data-msg-isIdCardNo="请输入正确的身份证号"
                                      />
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">所属客户</label>
                            <div class="col-sm-9">
                                <select class="selectpicker form-control" data-live-search="true" name="kaId" id="kaId" onchange="showStore()" data-rule-required="true" data-msg-required="请选择所属门店">
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="selectKa">
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">职务</label>
                            <div class="col-sm-9">
                                <select class="form-control select2" name="empType"   data-rule-required="true" data-msg-required="请选择职务">
                                    <option value="" >请选择</option>
                                    <option value="1">店员</option>
                                    <option value="2">审核人</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">联系电话</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="phone"  placeholder="联系电话"
                                       data-rule-required="true" data-msg-required="请录入联系电话"
                                       data-rule-iphone="true"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">佣金比例(%)</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="rate"
                                       data-rule-positiveIntegerNumAndzero="true" data-msg-positiveIntegerNumAndzero="请录入整数"
                                       placeholder="佣金比例"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="submit" id="btn-submit" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="nationModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header" style="background-color: #307095;">
                    <button type="button" class="close" data-dismiss="modal" id="btn_close" >
                        <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel5">员工-编辑</h4>
                </div>

                <div class="modal-body">
                    <form class="form-horizontal"  id="nationForm"  method="post">
                        <input type="hidden" class="form-control" name="empId"/>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">用户名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="loginName"
                                       data-rule-required="true" data-msg-required="请录入用户名"
                                       data-rule-minlength="12" data-msg-minlength="用户名最少12个字符"
                                       data-rule-maxlength="13" data-msg-maxlength="用户名最大为13个字符"
                                       data-rule-commonString ="true"
                                       placeholder="用户名(数字或字母)"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">姓名</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="empName" placeholder="姓名"
                                       data-rule-required="true" data-msg-required="请录入姓名"
                                       data-rule-minlength="2" data-msg-minlength="姓名最少2个字符"
                                       data-rule-maxlength="20" data-msg-maxlength="姓名最大为20个字符"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">身份证号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="cardNo" placeholder="身份证号"
                                       data-rule-required="true" data-msg-required="请录入身份证号"
                                       data-rule-isIdCardNo="true"  data-msg-isIdCardNo="请输入正确的身份证号"
                                />
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">所属客户</label>
                            <div class="col-sm-9">
                                 <select class="selectpicker form-control" data-live-search="true" name="kaId" id="kalist" onchange="changeStore()"
                                            data-rule-required="true" data-msg-required="请选择所属客户">
                                 </select>
                            </div>
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">所属门店</label>
                            <div class="col-sm-9">
                                <select class='form-control select2' name='storeId' id='inputStoreIds' data-rule-required='true' data-msg-required='请选择所属门店'>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">职务</label>
                            <div class="col-sm-9">
                                <select class="form-control select2" name="empType"   data-rule-required="true" data-msg-required="请选择职务">
                                    <option value="" >请选择</option>
                                    <option value="1">店员</option>
                                    <option value="2">审核人</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label  class="col-sm-3 control-label">联系电话</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="phone"  placeholder="联系电话"
                                       data-rule-required="true" data-msg-required="请录入联系电话"
                                       data-rule-iphone="true"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">佣金比例(%)</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="rate"
                                       data-rule-positiveIntegerNumAndzero="true" data-msg-positiveIntegerNumAndzero="请录入整数"
                                       placeholder="佣金比例"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="submit" id="btn-nationsub" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="checkModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" aria-hidden="true">
        <div class="modal-dialog" style="width: 780px;">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;">
                    <button type="button" class="close" data-dismiss="modal" id="btn_close" >
                        <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel3">订单审核-设置</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-xs-5"  >
                            <strong>没有审核订单权限的门店：</strong>
                            <select name="from" id="multiselect" class="form-control" size="8"  multiple="multiple">
                            </select>
                        </div>

                        <div class="col-xs-2">
                            <strong>操作：</strong>
                            <button type="button" id="multiselect_rightAll" class="btn btn-block"><i class="glyphicon glyphicon-forward"></i></button>
                            <button type="button" id="multiselect_rightSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-right"></i></button>
                            <button type="button" id="multiselect_leftSelected" class="btn btn-block"><i class="glyphicon glyphicon-chevron-left"></i></button>
                            <button type="button" id="multiselect_leftAll" class="btn btn-block"><i class="glyphicon glyphicon-backward"></i></button>
                        </div>

                            <div class="col-xs-5">
                                <strong>有审核订单权限的门店：</strong>
                                <select name="to" id="multiselect_to" class="form-control" size="8" multiple="multiple"></select>

                            </div>

                    </div>
                    <div class="form-group">
                        <span><code>注：左侧为该审核人没有审核权限的门店，若添加该审核人对其门店的订单的审核权限，
                            则选中后点击<strong>→</strong>（或双击）移动到右侧框内并提交。</code></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" id="check-submit" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="leadModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;">
                    <button type="button" class="close" data-dismiss="modal" id="btn_close" >
                        <span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel4">店员—导入</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal"  id="loadForm"  method="post">
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">所属客户</label>
                            <div class="col-sm-9">
                                <select class="form-control select2" name="kaId" id="kaIds" onchange="showStores()" data-rule-required="true" data-msg-required="请选择所属门店">
                                </select>
                            </div>
                        </div>
                        <div class="form-group" id="selectKas">
                        </div>
                        <div class="form-group" >
                            <label class="col-sm-3 control-label">导入文件</label>
                            <div class="col-sm-9">
                                <input type="file" style="margin-top: 4px;" id="file" name="file" value="" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">模板下载</label>
                            <div class="col-xs-9" style="padding-top: 8px;">
                                <a th:href="@{http://qhs-dev.oss-cn-shanghai.aliyuncs.com/%E5%BA%97%E5%91%98%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx}" > 下载导入模板</a>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="submit" id="btn-loading" class="btn btn-primary">导入</button>
                </div>
            </div>
        </div>
    </div>

    <form id="getlistForm">
        <shiro:hasRole name="sys_agency">
            <input type="hidden" th:name="agencyId" th:value="${session.authUser.userId}"/>
        </shiro:hasRole>
        <shiro:hasRole name="sys_nationwide">
            <input type="hidden" th:name="nationwideId" th:value="${session.authUser.userId}"/>
        </shiro:hasRole>
    </form>
    <!-- DataTables -->
    <script th:src="@{/bootstrap/js/multiselect.min.js}"></script>
    <script th:src="@{/bootstrap/js/multiselect.js}"></script>
    <script th:src="@{/plugins/jQuery/jquery.form.min.js}"></script>
    <script th:src="@{/plugins/bootstrap-select/bootstrap-select.min.js}"></script>
    <script>
        $(function (){
            var tables = $("#dataTable").dataTable({
                serverSide: true,//分页，取数据等等的都放到服务端去
                processing: true,//载入数据的时候是否显示“载入中”
                pageLength: 10,  //首次加载的数据条数
                ordering: false,//排序操作在服务端进行，所以可以关了。
                /*pagingType: "full_numbers",*/
                autoWidth: false,
                stateSave: true,//保持翻页状态，和tables.fnDraw(false);结合使用
                searching: false,
                ajax: {   //类似jquery的ajax参数，基本都可以用。
                    type: "post",//后台指定了方式，默认get，外加datatable默认构造的参数很长，有可能超过get的最大长度。
                    url: "/emp/list",
                    dataSrc: "data",//默认data，也可以写其他的，格式化table的时候取里面的数据
                    data: function (d) {//d是原始的发送给服务器的数据，默认很长。
                        var param = {}; //因为服务端排序，可以新建一个参数对象
                        param.draw = d.draw;
                        param.start = d.start;
                        param.length = d.length;
                        var formData = $("#queryForm").serializeArray();//把form里面的数据序列化成数组
                        formData.forEach(function (e) {
                            param[e.name] = e.value;
                        });
                        return param;//自定义需要传递的参数。
                    }
                },
                columns: [//对应上面thead里面的序列
                    {"data": 'loginName'},
                    {"data": 'empName'}, //mData 表示发请求时候本列的列明，返回的数据中相同下标名字的数据会填充到这一列
                    {"data": 'phone'},
                    {"data": 'empType',
                        "render":function (data,type,full,callback) {
                            if(data=='1')
                                return /*<![CDATA[*/"<span class='label label-success'>店员</span>"/*]]>*/;
                            else return /*<![CDATA[*/"<span class='label label-success'>审核人</span>"/*]]>*/;
                        }
                    },
                    {"data": 'status',
                        "render":function(data,type,full,callback) {
                            if(data==1)
                                return /*<![CDATA[*/"<span class='label label-primary'>待审核</span>"/*]]>*/;
                            if(data==0) return /*<![CDATA[*/"<span class='label label-danger'>禁用</span>"/*]]>*/;
                            if(data==2 || data==3) return /*<![CDATA[*/"<span class='label label-success'>启用</span>"/*]]>*/;
                            if(data==4) return /*<![CDATA[*/"<span class='label label-danger'>审核未通过</span>"/*]]>*/;
                        }
                    },
                    {"data": 'rate'},
                    {"data": 'totalMoney',
                        "render":function(data,type,full,callback) {
                            if(data!=null)
                                return data+"元";
                            else
                                return 0;
                        }
                    },
                    {"data": 'frozenMoney',
                        "render":function(data,type,full,callback) {
                            if(data!=null)
                                return data+"元";
                            else
                                return 0;
                        }
                    },
                    {"data": 'balanceMoney',
                        "render":function(data,type,full,callback) {
                            if(data!=null)
                                return data+"元";
                            else
                                return 0;
                        }
                    },
                    {"data": 'createTimeDate', defaultContent: ""}
                    <shiro:hasRole name="sys_agency">
                    ,{"data": "status","width":"210px",
                        "render":function(data,type,full,callback) {
                            /*<![CDATA[*/
                            if(data==0){
                                return "<div class='btn-group'><button id='editRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>" +
                                    "<div class='btn-group'><button id='useRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-check'></i>启用</button></div>"
                            }if(data==2 || data == 3){
                                return "<div class='btn-group'><button id='checkOrder' class='btn btn-primary btn-sm' type='button'><i class='fa fa-gear'></i>审核设置</button>" +
                                    "<div class='btn-group'><button id='editRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>" +
                                    "<div class='btn-group'><button id='forbidRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-close'></i>禁用</button>"
                            }
                            if(data==1){
                                return "<div class='btn-group'><button id='editRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>"
                            }
                            if(data==4){
                                return "<div class='btn-group'><button id='editcheckRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>修改信息</button>"
                            }
                            /*]]>*/
                        }
                }
                </shiro:hasRole>
            <shiro:hasRole name="sys_nationwide">
                ,{"data": "status","width":"210px",
                "render":function(data,type,full,callback) {
                    /*<![CDATA[*/
                    if(data==0){
                        return "<div class='btn-group'><button id='nationRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>" +
                            "<div class='btn-group'><button id='useRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-check'></i>启用</button></div>"
                    }if(data==2 || data == 3){
                        return"<div class='btn-group'><button id='nationRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>" +
                            "<div class='btn-group'><button id='forbidRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-close'></i>禁用</button>" +
                            "<div class='btn-group'><button id='smsRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>短信重发</button>"
                    }
                    if(data==1){
                        return "<div class='btn-group'><button id='nationRow' class='btn btn-primary btn-sm' type='button'><i class='fa fa-edit'></i>编辑</button>"
                    }
                    if(data==4){
                        return "";
                    }
                    /*]]>*/
                }
            }
            </shiro:hasRole>
            ],

            /*<![CDATA[*/
                dom: '<"toolbar">frtip',
                    /*]]>*/

                //每加载完一行的回调函数
                createdRow: function( row, data, index ) {
                //修改单元格样式
                //$('td', row).eq(5).css('font-weight',"bold").css("color","red");//获取到具体行具体格的元素
            },
            initComplete: function (setting, json) {
                //初始化完成之后替换原先的搜索框。
            },


            language: {
                lengthMenu: "",//不显示记录条数选择
                    //lengthMenu: '<select class="form-control input-xsmall">' + '<option value="5">5</option>' + '<option value="10">10</option>' + '<option value="20">20</option>' + '<option value="30">30</option>' + '<option value="40">40</option>' + '<option value="50">50</option>' + '</select>条记录',//左上角的分页大小显示。
                    processing: "加载中",//处理页面数据的时候的显示
                        /*<![CDATA[*/
                    paginate: {//分页的样式文本内容。
                    previous: "<",
                        next: ">",
                        first: "<<",
                        last: ">>"
                },
                /*]]>*/
                zeroRecords: "没有数据",//table tbody内容为空时，tbody的内容。
                    //下面三者构成了总体的左下角的内容。
                    //info: "共 _PAGES_ 页，显示第 _START_ 到第 _END_ 条 ",//筛选之后得到 _TOTAL_ 条，初始 _MAX_ 条   左下角的信息显示，大写的词为关键字。
                    info: "共 _PAGES_ 页，显示第 _START_ 到第 _END_ 条",
                    infoEmpty: "0条记录",//筛选为空时左下角的显示。0条记录
                    infoFiltered: "",//筛选之后的左下角筛选提示(另一个是分页信息显示，在上面的info中已经设置，所以可以不显示)，
                    sSearch: "关键字："
            }

        });
            <shiro:hasRole name="sys_agency">

                $("div.toolbar").html('<button type="button" class="btn btn-primary btn-sm" id="btn-add">新增</button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-primary btn-sm" id="btn-lead">批量导入</button>&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-primary btn-sm" id="btn-down">导出excel</button>');

           </shiro:hasRole>
            <shiro:hasRole name="sys_nationwide">
                $("div.toolbar").html('<button type="button" class="btn btn-primary btn-sm" id="btn-down">导出excel</button>');
            </shiro:hasRole>
            //查询按钮
            $("#btn-query").on("click", function () {
                tables.fnDraw();
            });
            //导出按钮
            $("#btn-down").on("click", function () {
                /*<![CDATA[*/
                $("div.toolbar button").hide();
                $("div.toolbar").append("<div class='progress active' style='width: 500px;height: 25px;'><div class='progress-bar progress-bar-primary progress-bar-striped' id='progress-bar'" +
                    " role='progressbar' aria-valuenow='10' aria-valuemin='0' aria-valuemax='100' style='width: 10%'>导出中...</div></div>")
                /*]]>*/
                var form = $("#queryForm");
                form.attr('target','');
                form.attr('method','post');
                form.attr('action','/emp/exportXls');
                form.submit();
                var timer =  setInterval(function () {
                    $.ajax({
                        url: '/emp/isExport',
                        type: 'POST',
                        dataType: "json",
                        cache: "false",
                        success: function (result) {
                            if (result.result == 200) {
                                /*<![CDATA[*/
                                var now = parseInt($("#progress-bar").attr("aria-valuenow")) +20;
                                if(now < 121){
                                    $("#progress-bar").attr("aria-valuenow",now);
                                    $("#progress-bar").attr("style","width:"+now+"%");
                                }
                                /*]]>*/
                            }else{
                                /*<![CDATA[*/
                                $("div.toolbar button").show();
                                $("div.toolbar div ").remove();
                                /*]]>*/
                                clearInterval(timer);
                            }
                        }
                    })
                },"1000");
            });

            $("#btn-lead").on("click", function () {
                $.ajax({
                    url: '/store/getkaList',
                    type: 'POST',
                    dataType: "json",
                    data:$("#getlistForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            /*<![CDATA[*/
                            $("#kaIds").append("<option value='' ></option>");
                            /*]]>*/
                            $.each(result.data, function (i, n) {
                                /*<![CDATA[*/
                                $("#kaIds").append("<option value='" + n.kaId + "'>" + n.kaName + "</option>")
                                /*]]>*/
                            });
                        }else{
                            toastr.error(result.msg);
                            return;
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#leadModal").modal("show");
            })
            var validateload = $("#loadForm").validate();
            $("#btn-loading").on("click",function(){
                if(validateload.form()){
                    $("#btn-loading").attr("disabled",true);
                    $("#loadForm").ajaxSubmit({
                        url: '/emp/importemps',
                        type: 'POST',
                        dataType: "json",
                        cache: "false",
                        success:function (data) {
                            if (data.result == "200") {
                                $("#leadModal").modal("hide");
                                tables.fnDraw();
                                toastr.success(data.msg);
                                $("#btn-loading").attr("disabled",false);
                            }
                        },
                        error:function (request) {
                            $("#btn-loading").attr("disabled",false);
                            toastr.error("网络错误...");
                        }
                    })
                }
            })
            $('#leadModal').on('hide.bs.modal', function () {
                $("#kaIds > option").remove();
                $("#selectKas label").remove();
                $("#selectKas div").remove();
                $("#selectKas select").remove();
            });
            var url="/emp/edit";
            //添加
            $("#btn-add").on("click", function () {
                $("#editForm div").removeClass('has-success');
                $("#kaId").attr("disabled",false);
                $("#inputStoreId").attr("disabled",false);
                $.ajax({
                    url: '/store/getkaList',
                    type: 'POST',
                    dataType: "json",
                    data:$("#getlistForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        var tempAjax = "";
                        if (result.result == 200) {
                            /*<![CDATA[*/
                            tempAjax += "<option value='' ></option>";
                            $.each(result.data, function (i, n) {

                                tempAjax += "<option value='" + n.kaId + "'>" + n.kaName + "</option>";
                               

                            });
                            
                            $("#kaId").append(tempAjax);
                            //更新内容刷新到相应的位置
                            $('#kaId').selectpicker('refresh');
                            $('#kaId').selectpicker('render');
                        }else{
                            toastr.error(result.msg);
                            return;
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                 $("#editModal input[name=status]").val("");
                    $("#editModal input[name=empId]").val(null);
                    $("#editModal input[name=loginName]").val("");
                   $("#editModal input[name=loginName]").attr("disabled",false);
                    $("#editModal input[name=empName]").val("");
                    $("#editModal select[name=empType]").val("");
                    $("#editModal input[name=cardNo]").val("");
                    //$("#editModal input[name=password]").val(null);
                    $("#editModal input[name=phone]").val("");
                    //$("#editModal input[name=phone]").removeAttrs("readonly")
                    $("#editModal input[name=email]").val("");
                    //$("#editModal select[name=status]").val("");
                    $("#editModal input[name=rate]").val("");

                    $("#myModalLabel2").text("店员-新增");
                    $("#editModal").modal("show");

            });

            $("#btn_close").click(function () {
                $("#editModal").css('display','none');
                //$("#forPassword > label").show();
                // $("#password").attr("type","password");
                $("#inputStoreId > option").remove();
            })
            $("#dataTable tbody").on("click", "#smsRow", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                $("#smsRow").attr("disabled",true);
                $.ajax({
                    cache: false,
                    type: "POST",
                    url: "/emp/smsResend",
                    data: {"empId":data.empId},
                    dataType: "json",
                    async: false,
                    error: function (request) {
                        $("#smsRow").attr("disabled",false);
                        toastr.error("网络错误...");
                    },
                    success: function (data) {
                        if (data.result == "200") {
                            toastr.success(data.msg);
                            $("#smsRow").attr("disabled",false);
                        } else {
                            $("#smsRow").attr("disabled",false);
                            toastr.error(data.msg);
                        }
                    }
                });
            })
            $('#nationModal').on('hide.bs.modal', function () {
                $("#inputStoreIds > option").remove();
                $("#kalist > option").remove();
                $('#kalist').selectpicker('refresh');
                $('#kalist').selectpicker('render');
            });
            //全国编辑
            $("#dataTable tbody").on("click", "#nationRow", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                $("#nationModal input[name=empId]").val(data.empId);
                $("#nationModal input[name=loginName]").val(data.loginName);
                $("#nationModal input[name=loginName]").attr("readonly","readonly");
                $("#nationModal input[name=empName]").val(data.empName);
                $("#nationModal select[name=empType]").val(data.empType);

                $("#nationModal input[name=cardNo]").val(data.cardNo);
                $.ajax({
                    url: '/store/getkaList',
                    type: 'POST',
                    dataType: "json",
                    data:$("#getlistForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            /*<![CDATA[*/
                            $.each(result.data, function (i, n) {
                                if(data.kaId == n.kaId){
                                    $("#kalist").append("<option value='" + n.kaId + "' selected='selected'>" + n.kaName + "</option>")
                                }else{
                                    $("#kalist").append("<option value='" + n.kaId + "'>" + n.kaName + "</option>")
                                }
                                //更新内容刷新到相应的位置
                                $('#kalist').selectpicker('refresh');
                                $('#kalist').selectpicker('render');
                            })
                            /*]]>*/
                        }else{
                                toastr.error(result.msg);
                                return;
                            }
                        },
                        error:function(err){
                            toastr.error("网络错误...");
                        }
                });
                $.ajax({
                    url:'/emp/getStoreList',
                    type:'POST',
                    data:{"kaId":data.kaId},
                    dataType: "json",
                    cache: "false",
                    success:function(result){
                        if(result.result==200 ){
                            if(data.storeId==null){
                                /*<![CDATA[*/
                                $("#inputStoreIds").append("<option value='' ></option>");
                                /*]]>*/
                            }
                            $.each(result.data,function(i,n){
                                /*<![CDATA[*/
                                if(n.storeId==data.storeId){
                                    /*$("#inputStoreId").attr("disabled",true);*/
                                    $("#inputStoreIds").append("<option value='"+n.storeId+"' selected='selected'>"+n.storeName+"</option>");
                                }else {
                                    $("#inputStoreIds").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                                }
                                /*]]>*/
                            });
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#nationModal input[name=phone]").val(data.phone);
                $("#nationModal input[name=rate]").val(data.rate);

                $("#nationModal").modal("show");
            })
            var validateNation = $("#nationForm").validate();
            $("#btn-nationsub").click(function(){
                if(validateNation.form()){
                    $("#btn-nationsub").attr("disabled",true);
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: url,
                        data: $("#nationForm").serialize(),
                        dataType: "json",
                        async: false,
                        error: function (request) {
                            $("#btn-nationsub").attr("disabled",false);
                            toastr.error("网络错误...");
                        },
                        success: function (data) {
                            //   data = $.parseJSON(data);
                            if (data.result == "200") {
                                $("#nationModal").modal("hide");
                                tables.fnDraw();
                                toastr.success(data.msg);
                                $("#btn-nationsub").attr("disabled",false);
                            } else {
                                $("#btn-nationsub").attr("disabled",false);
                                toastr.error(data.msg);
                            }
                        }
                    });
                }
            })
            //左右选择框
            $('#checkModal').on('hide.bs.modal', function () {
                $("#multiselect input").remove();
                $("#multiselect > option").remove();
                $("#multiselect_to > option").remove();
            });
            $("#multiselect").multiselect();
            $("#dataTable tbody").on("click", "#checkOrder", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                if(data.empType!=2){
                    toastr.error("该用户不能设置审核订单的权限，请选择审核人！");
                    return
                }else{
                    //获取该用户对应的ka下的所有门店 同时获取该用户具有审核权限的门店
                    $.ajax({
                        url: '/emp/getStoreList',
                        data:{"kaId":data.kaId},
                        type: 'POST',
                        dataType: "json",
                        cache: "false",
                        success: function (result) {
                            if (result.result == 200) {
                                $.ajax({
                                    url: '/emp/getCheckList',
                                    data: {"empId": data.empId},
                                    type: 'POST',
                                    dataType: "json",
                                    cache: "false",
                                    success: function (res) {
                                        if(res.result == 200){
                                            /*<![CDATA[*/
                                            $("#multiselect").append("<input type='hidden' id='empId' name='empId' value='"+data.empId+"'/>")
                                            var storeArr = new Array();
                                            $.each(res.data,function (x,y) {
                                                storeArr.push(y.storeId);
                                                $("#multiselect_to").append("<option value='"+y.storeId+"'>"+y.storeName+"</option>")
                                            })
                                            $.each(result.data,function (i,n){
                                                    if(!contains(storeArr,n.storeId)){
                                                        $("#multiselect").append("<option value='"+n.storeId+"'>"+n.storeName+"</option>")
                                                    }
                                            })

                                            /*]]>*/
                                        }
                                    }
                                });

                            }else{
                                toastr.error(result.msg);
                                return;
                            }
                        },
                        error:function(err){
                            toastr.error("网络错误...");
                        }
                    })
                    $("#checkModal").modal("show");
                }

            })
            $("#check-submit").click(function(){
                var ids = new Array() ;
                $("#multiselect_to option").each(function () {
                    var val = $(this).val();
                    ids.push(val);
                })
                if(ids.length>0){
                    var empId = $("#multiselect").find("input").val();
                    var storeIds = ids.toString();
                    $("#check-submit").attr("disabled",true);
                    $.ajax({
                        url: '/emp/saveCheckForm',
                        data:{"empId":empId,"ids":storeIds},
                        type: 'POST',
                        dataType: "json",
                        cache: "false",
                        success: function (result) {
                            if (result.result == 200) {
                                $("#check-submit").attr("disabled",false);
                                $("#checkModal").modal("hide");
                                toastr.success(result.msg);
                            }else{
                                $("#check-submit").attr("disabled",false);
                                toastr.error(result.msg);
                                return;
                            }
                        },
                        error:function(err){
                            $("#check-submit").attr("disabled",false);
                            toastr.error("网络错误...");
                        }
                    })
                }else{
                    $("#checkModal").modal("hide");
                }
            })
            //修改
            $("#dataTable tbody").on("click", "#editRow", function () {
                $("#editForm div").removeClass('has-success');
                var data = tables.api().row($(this).parents("tr")).data();
                $("#kaId").attr("disabled",true);

                $.ajax({
                    url: '/store/getkaList',
                    type: 'POST',
                    dataType: "json",
                    data:$("#getlistForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            /*<![CDATA[*/
                            $("#kaId").append("<option value='' ></option>");
                            /*]]>*/
                            $.each(result.data, function (i, n) {
                                /*<![CDATA[*/
                                if(data.kaId == n.kaId){
                                    $("#kaId").append("<option value='" + n.kaId + "' selected='selected'>" + n.kaName + "</option>")
                                }else{
                                    $("#kaId").append("<option value='" + n.kaId + "'>" + n.kaName + "</option>")
                                }
                                $('#kaId').selectpicker('refresh');
                                $('#kaId').selectpicker('render');
                                /*]]>*/
                            });
                        }else{
                            toastr.error(result.msg);
                            return;
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#selectKa").text("");
                var kaId = data.kaId;
                /*<![CDATA[*/
                $("#selectKa").append("<label class='col-sm-3 control-label'>所属门店</label><div class='col-sm-9'><select class='form-control select2' name='storeId' id='inputStoreId' data-rule-required='true' data-msg-required='请选择所属门店'></select></div>");
                /*]]>*/
                $.ajax({
                    url:'/emp/getStoreList',
                    type:'POST',
                    data:{"kaId":kaId},
                    dataType: "json",
                    cache: "false",
                    success:function(result){
                        if(result.result==200 ){
                            if(data.storeId==null){
                                /*<![CDATA[*/
                                $("#inputStoreId").append("<option value='' ></option>");
                                /*]]>*/
                            }
                            $.each(result.data,function(i,n){
                                /*<![CDATA[*/
                                if(n.storeId==data.storeId){
                                    /*$("#inputStoreId").attr("disabled",true);*/
                                    $("#inputStoreId").append("<option value='"+n.storeId+"' selected='selected'>"+n.storeName+"</option>");
                                }else {
                                    $("#inputStoreId").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                                }
                                /*]]>*/
                            });
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#editModal input[name=stauts]").val(data.status);
                $("#editModal input[name=empId]").val(data.empId);
                $("#editModal input[name=loginName]").val(data.loginName);
                $("#editModal input[name=loginName]").attr("disabled",true);
                $("#editModal input[name=empName]").val(data.empName);
                $("#editModal select[name=empType]").val(data.empType);
                $("#editModal input[name=phone]").val(data.phone);
                $("#editModal input[name=cardNo]").val(data.cardNo);
                //$("#editModal input[name=phone]").attr("readonly","readonly");
                $("#editModal input[name=email]").val(data.email);
                $("#editModal input[name=rate]").val(data.rate);

                $("#editModal").modal("show");
            });
            var validater = $("#editForm").validate();
            //修改信息重新提交
            $("#dataTable tbody").on("click", "#editcheckRow", function (){
                $("#editForm div").removeClass('has-success');
                var data = tables.api().row($(this).parents("tr")).data();
                $.ajax({
                    url: '/store/getkaList',
                    type: 'POST',
                    dataType: "json",
                    data:$("#getlistForm").serialize(),
                    cache: "false",
                    success: function (result) {
                        if (result.result == 200) {
                            /*<![CDATA[*/
                            $("#kaId").append("<option value='' ></option>");
                            /*]]>*/
                            $.each(result.data, function (i, n) {
                                /*<![CDATA[*/
                                if(data.kaId == n.kaId){
                                    $("#kaId").append("<option value='" + n.kaId + "' selected='selected'>" + n.kaName + "</option>")
                                }else{
                                    $("#kaId").append("<option value='" + n.kaId + "'>" + n.kaName + "</option>")
                                }
                                $('#kaId').selectpicker('refresh');
                                $('#kaId').selectpicker('render');
                                /*]]>*/
                            });
                        }else{
                            toastr.error(result.msg);
                            return;
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#selectKa").text("");
                var kaId = data.kaId;
                /*<![CDATA[*/
                $("#selectKa").append("<label class='col-sm-3 control-label'>所属门店</label><div class='col-sm-9'><select class='form-control select2' name='storeId' id='inputStoreId' data-rule-required='true' data-msg-required='请选择所属门店'></select></div>");
                /*]]>*/
                $.ajax({
                    url:'/emp/getStoreList',
                    type:'POST',
                    data:{"kaId":kaId},
                    dataType: "json",
                    cache: "false",
                    success:function(result){
                        if(result.result==200 ){
                            if(data.storeId==null){
                                /*<![CDATA[*/
                                $("#inputStoreId").append("<option value='' ></option>");
                                /*]]>*/
                            }
                            $.each(result.data,function(i,n){
                                /*<![CDATA[*/
                                if(n.storeId==data.storeId){
                                    /*$("#inputStoreId").attr("disabled",true);*/
                                    $("#inputStoreId").append("<option value='"+n.storeId+"' selected='selected'>"+n.storeName+"</option>");
                                }else {
                                    $("#inputStoreId").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                                }
                                /*]]>*/
                            });
                        }
                    },
                    error:function(err){
                        toastr.error("网络错误...");
                    }
                });
                $("#editModal input[name=status]").val("1");
                $("#editModal input[name=empId]").val(data.empId);
                var str = data.loginName.substr(0,data.loginName.length-5);
                $("#editModal input[name=loginName]").val(str);
                //$("#editModal input[name=loginName]").attr("disabled",true);
                $("#editModal input[name=empName]").val(data.empName);
                $("#editModal select[name=empType]").val(data.empType);
                $("#editModal input[name=phone]").val(data.phone);
                $("#editModal input[name=cardNo]").val(data.cardNo);
                //$("#editModal input[name=phone]").attr("readonly","readonly");
                $("#editModal input[name=email]").val(data.email);
                $("#editModal input[name=rate]").val(data.rate);

                $("#editModal").modal("show");
            })
            //添加、修改  表单异步提交
            $("#btn-submit").on("click", function(){
                if(validater.form()) {
                    $("#kaId").attr("disabled",false);
                    $("#inputStoreId").attr("disabled",false);
                    $("#btn-submit").attr("disabled",true);
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: url,
                        data: $("#editForm").serialize(),
                        dataType: "json",
                        async: false,
                        error: function (request) {
                            toastr.error("网络错误...");
                        },
                        success: function (data) {
                            //   data = $.parseJSON(data);
                            if (data.result == "200") {
                                $("#editModal").modal("hide");
                                tables.fnDraw();
                                toastr.success(data.msg);
                                $("#btn-submit").attr("disabled",false);
                                $("#inputStoreId > option").remove();
                            } else {
                                $("#btn-submit").attr("disabled",false);
                                toastr.error(data.msg);
                            }
                        }
                    });
                }
            });
            //启用
            $("#dataTable tbody").on("click", "#useRow", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                bootbox.confirm(
                    {
                        message: "确认要启用该账户吗",
                        buttons: {
                            confirm: {
                                label: '确认'
                            },
                            cancel: {
                                label: '取消'
                            }
                        },
                        callback: function (result) {
                            // 返回 true  或者false
                            if (result) {
                                $.ajax({
                                    url: '/emp/useEmp/' + data.empId,
                                    type: 'POST',
                                    dataType: "json",
                                    cache: "false",
                                    success: function (result) {
                                        if (result.result == 200) {
                                            tables.fnDraw();
                                            toastr.success(result.msg);
                                        } else {
                                            toastr.error(result.msg);
                                        }
                                    },
                                    error: function (err) {
                                        toastr.error("网络错误...");
                                    }
                                });
                            }
                        }
                    });
            })
            $("#dataTable tbody").on("click", "#forbidRow", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                bootbox.confirm(
                    {
                        message: "确认要禁用该账户吗",
                        buttons: {
                            confirm: {
                                label: '确认'
                            },
                            cancel: {
                                label: '取消'
                            }
                        },
                        callback: function (result) {
                            // 返回 true  或者false
                            if (result) {
                                $.ajax({
                                    url: '/emp/forbid/' + data.empId,
                                    type: 'POST',
                                    dataType: "json",
                                    cache: "false",
                                    success: function (result) {
                                        if (result.result == 200) {
                                            tables.fnDraw();
                                            toastr.success(result.msg);
                                        } else {
                                            toastr.error(result.msg);
                                        }
                                    },
                                    error: function (err) {
                                        toastr.error("网络错误...");
                                    }
                                });
                            }
                        }
                    });
            });
            //删除
            $("#dataTable tbody").on("click", "#delRow", function () {
                var data = tables.api().row($(this).parents("tr")).data();
                bootbox.confirm(
                    {
                        message: "确认要删除吗",
                        buttons: {
                            confirm: {
                                label: '确认'
                            },
                            cancel: {
                                label: '取消'
                            }
                        },
                        callback: function (result) {
                            // 返回 true  或者false
                            if (result) {
                                $.ajax({
                                    url:'/emp/delete',
                                    type:'POST',
                                    data:{"empId":data.empId},
                                    dataType: "json",
                                    cache: "false",
                                    success:function(result){
                                        if(result.result == 200){
                                            toastr.success(result.msg);
                                            tables.api().row().remove().draw(false);
                                        }else{
                                            toastr.error(result.msg);
                                        }
                                    },
                                    error:function(err){
                                        toastr.error("网络错误...");
                                    }
                                });
                            }
                        }
                    });


            });
            $('#editModal').on('hide.bs.modal', function () {
                $("#kaId > option").remove();
                $("#selectKa label").remove();
                $("#selectKa div").remove();
                $("#selectKa select").remove();
            });
            /*<![CDATA[*/
            $.each(province, function (k, p) {
                var option = "<option value='" + p.ProID + "'>" + p.ProName + "</option>";
                $("#selProvince").append(option);
            });

            $("#selProvince").change(function () {
                var selValue = $(this).val();
                $("#selCity option:gt(0)").remove();

                $.each(city, function (k, p) {
                    if (p.ProID == selValue) {
                        var option = "<option value='" + p.CityID + "'>" + p.CityName + "</option>";
                        $("#selCity").append(option);
                    }
                });

            });

            $("#selCity").change(function () {
                var selValue = $(this).val();
                $("#selDistrict option:gt(0)").remove();

                $.each(District, function (k, p) {
                    if (p.CityID == selValue) {
                        var option = "<option value='" + p.Id + "'>" + p.DisName + "</option>";
                        $("#selDistrict").append(option);
                    }
                });
            });
            /*]]>*/


        })
        function showStores() {
            var kaId = $("#kaIds").val();
            /*<![CDATA[*/
            $("#selectKas").text("");
            $("#selectKas").append("<label class='col-sm-3 control-label'>所属门店</label><div class='col-sm-9'><select class='form-control select2' name='storeId' id='inputStoreId' data-rule-required='true' data-msg-required='请选择所属门店'></select></div>");
            /*]]>*/
            $.ajax({
                url:'/emp/getStoreList',
                type:'POST',
                data:{"kaId":kaId},
                dataType: "json",
                cache: "false",
                success:function(result){
                    if(result.result==200 ){
                        /*<![CDATA[*/
                        $("#inputStoreId").append("<option value='' ></option>");
                        /*]]>*/
                        $.each(result.data,function(i,n){
                            /*<![CDATA[*/
                            $("#inputStoreId").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                            /*]]>*/
                        });
                    }
                },
                error:function(err){
                    toastr.error("网络错误...");
                }
            });
        }
        function showStore() {
            var kaId = $("#kaId").val();
            /*<![CDATA[*/
            $("#selectKa").text("");
            $("#selectKa").append("<label class='col-sm-3 control-label'>所属门店</label><div class='col-sm-9'><select class='form-control select2' name='storeId' id='inputStoreId' data-rule-required='true' data-msg-required='请选择所属门店'></select></div>");
            /*]]>*/
            $.ajax({
                url:'/emp/getStoreList',
                type:'POST',
                data:{"kaId":kaId},
                dataType: "json",
                cache: "false",
                success:function(result){
                    if(result.result==200 ){
                            /*<![CDATA[*/
                            $("#inputStoreId").append("<option value='' ></option>");
                            /*]]>*/
                        $.each(result.data,function(i,n){
                            /*<![CDATA[*/
                                $("#inputStoreId").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                            /*]]>*/
                        });
                    }
                },
                error:function(err){
                    toastr.error("网络错误...");
                }
            });
        }
        function changeStore(){
            var kaId = $("#kalist").val();
            $("#inputStoreIds option").remove();
            $.ajax({
                url:'/emp/getStoreList',
                type:'POST',
                data:{"kaId":kaId},
                dataType: "json",
                cache: "false",
                success:function(result){
                    if(result.result==200 ){
                        /*<![CDATA[*/
                        $("#inputStoreIds").append("<option value='' ></option>");
                        /*]]>*/
                        $.each(result.data,function(i,n){
                            /*<![CDATA[*/
                            $("#inputStoreIds").append("<option value='" + n.storeId + "' >" + n.storeName + "</option>");
                            /*]]>*/
                        });
                    }
                },
                error:function(err){
                    toastr.error("网络错误...");
                }
            });

        }
        function contains(arr, obj) {
            var i = arr.length;
            while (i--) {
                if (arr[i] === obj) {
                    return true;
                }
            }
            return false;
        }


    </script>


</div>
</body>
</html>
